/**
 * File: Supercontig.java
 * Created by: mhaimel
 * Created on: 31 Mar 2009
 * CVS:  $Id: Supercontig.java,v 1.3 2009/08/11 10:32:20 mhaimel Exp $
 */
package uk.ac.ebi.velvet.model;

import java.io.File;
import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

import uk.ac.ebi.curtain.util.VelvetExec;
import uk.ac.ebi.curtain.utils.data.FileType;
import uk.ac.ebi.curtain.utils.data.ReadType;
import uk.ac.ebi.curtain.utils.file.FileInfo;
import uk.ac.ebi.velvet.processor.impl.WalkingGuide;

/**
 * @author mhaimel
 *
 */
public class Supercontig implements Serializable {
	public static final String FILE_SUMMARY = "summary.txt";
	public static final String FILE_NODE_ID = "node_id.txt";
	public static final String FILE_CTG_ID = "ctg_id.txt";
	public static final String FILE_ARC_ID = "arc_id.txt";
	
	private int superContigId = -1;
	private WalkingGuide guide = null;
	private File baseDir = null;

	public Supercontig() {
		// TODO Auto-generated constructor stub
	}
	
	public Supercontig(int superContigId, WalkingGuide guide, File baseDir) {
		super();
		this.superContigId = superContigId;
		this.guide = guide;
		this.baseDir = baseDir;
	}
	
	public int getSuperContigId() {
		return superContigId;
	}

	public void setSuperContigId(int superContigId) {
		this.superContigId = superContigId;
	}

	public WalkingGuide getGuide() {
		return guide;
	}

	public void setGuide(WalkingGuide contigData) {
		this.guide = contigData;
	}

	public File getBaseDir() {
		return baseDir;
	}

	public void setBaseDir(File baseDir) {
		this.baseDir = baseDir;
	}
	
	public File getSummaryOutputFile() {
		return getSummaryOutputFile(this.getBaseDir());
	}
	public FileInfo getReadOutputFile() {
		return getReadOutputFile(this.getBaseDir());
	}
	public FileInfo getPairedReadOutputFile(Integer cat) {
		return getPairedReadOutputFile(this.getBaseDir(),cat);
	}
	public FileInfo getContigDumpFile() {
		return getContigDumpFile(this.getBaseDir());
	}
	
	public static File getSummaryOutputFile(File baseDir) {
		return new File(baseDir,FILE_SUMMARY);
	}
	public static File getArcIdOutputFile(File baseDir) {
		return new File(baseDir,FILE_ARC_ID);
	}

	public static File getContigIdOutputFile(File baseDir) {
		return new File(baseDir,FILE_CTG_ID);
	}
	
	public static File getNodeIdOutputFile(File baseDir) {
		return new File(baseDir,FILE_NODE_ID);
	}

	public static FileInfo getReadOutputFile(File baseDir) {
		return buildFileName(baseDir,FileType.fasta, ReadType.Short,StringUtils.EMPTY); 
	}

	public static FileInfo getPairedReadOutputFile(File baseDir,Integer cat) {
		return buildFileName(baseDir,FileType.fasta, ReadType.ShortPaired, cat);
	}
	
	public static File getCategoryInfoFile(File baseDir,Integer cat) {
		return new File(baseDir,"info_"+cat+".txt");
	}

	public static FileInfo getContigDumpFile(File baseDir) {
		return getContigDumpFile(baseDir,StringUtils.EMPTY);
	}
	
	public static FileInfo getContigDumpFile(File baseDir,String type) {
		return buildFileName(baseDir,FileType.fasta, ReadType.Contig,type);
	}
	
	private static FileInfo buildFileName(File baseDir, FileType fType, ReadType rType, String type) {
		String fileName = rType+"_"+type+ fType.getPostfix();
		return new FileInfo(new File(baseDir,fileName),fType,rType);
	}

	private static FileInfo buildFileName(File baseDir, FileType fType, ReadType rType, Integer category){
		String fileName = rType+"_"+ category + fType.getPostfix();
		return new FileInfo(new File(baseDir,fileName),fType,rType);		
	}

	public static String getVelvetDirName(Integer kmer) {
		return VelvetExec.DEFAULT_NAME+"_"+kmer;
	}
	
}
